import os
import sys
import django

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent
sys.path.append(str(BASE_DIR))

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'five_class_demo.settings')
django.setup()

from www import models

coupon_list = []
with open("coupon.csv", mode='r', encoding='utf-8') as fp:
    for line in fp:
        memo, code = line.strip().rsplit(",", maxsplit=1)
        coupon_list.append(models.Coupon(code=code, memo=memo))

models.Coupon.objects.bulk_create(coupon_list, batch_size=20)
